$.ajax({
    type: 'get',
    url: '/slides',
    success: function (res) {
        console.log(res);
        var html = template('slidesTpl', { data: res });
        $('#slidesBox').html(html);
    }
});
$('#file').on('change', function () {
    var file = this.files[0];
    var formData = new FormData();
    formData.append('avatar', file)
    $.ajax({
        type: 'post',
        url: '/upload',
        data: formData,
        //告诉 ajax 方法，不要处理 formdata 参数的格式 
        processData: false,
        //告诉 ajax 不设置文件类型 
        contentType: false,
        success: function (res) {
            $('#image').val(res[0].avatar)
        }
    })
});
$('#slidesForm').on('submit', function () {
    var formData = $(this).serialize();
    $.ajax({
        type: 'post',
        url: '/slides',
        data: formData,
        success: function () {
            location.reload()
        }
    })
    return false;
});
$('#slidesBox').on('click', '.delete', function () {
    var id = $(this).attr('data-id');
    if (confirm('您真的要删除这张图片吗？')) {
        $.ajax({
            type: 'delete',
            url: '/slides/' + id,
            success: function () {
                location.reload()
            }
        })
    }
})
